<?php

require_once($_SERVER['DOCUMENT_ROOT'].'/incofarming/Functions/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/incofarming/Functions/class/koperasi_model.php');



$koperasi_model = new Koperasi_model();

if(isset($_GET['params'])){

$params = $_GET['params'];

$params_explode = explode(',', $params, -1);

$where_kop_arr = "";
$where_kota_arr = "";

$arr_tmp = explode("-", $params_explode[0]);


for($i=0; $i<count($params_explode); $i++){
	$arr_tmp = explode("-", $params_explode[$i]);
	
	
	if($arr_tmp[0] == "NAMAKOTA"){
		if($where_kota_arr != "") $where_kota_arr .= " AND ";
		$where_kota_arr .= $arr_tmp[0]." LIKE '%".$arr_tmp[1]."%'";//echo $where_kota_arr;
		
	} else {
		if($where_kop_arr != "") $where_kop_arr .= " AND ";
		$where_kop_arr .= $arr_tmp[0]." LIKE '%".$arr_tmp[1]."%'";
		
	}
	
	/* $arr_tmp2 = array(
		'key' => $arr_tmp[0],
		'value' => $arr_tmp[1]
	);
	$params_arr[] = $arr_tmp2; */
} 

if($where_kota_arr == "") $param_tmp = $where_kop_arr;
else $param_tmp = $where_kop_arr.' AND '.$where_kota_arr;

$cruds_result = $koperasi_model->get_koperasi_data_param($param_tmp);

}

else {

$cruds_result = $koperasi_model->get_koperasi_data();

}

$params_arr = array();
//echo $cruds_result;

$count = 0;$index = 0;
while($row = mysql_fetch_array($cruds_result)){
	$param_temp = array(
		'id_kop' => $row['IDKOPERASI'],
		'nama_kop' => $row['NAMAKOPERASI'],
		'no_telp' => $row['NOTELP'],
		'no_fax' => $row['NOFAX'],
		'tgl_berdiri' => $row['TGLBERDIRI'],
		'info' => $row['INFORMASI'],
		'kota' => $row['NAMAKOTA'],
		'prov' => $row['NAMAPROPINSI'],
		'kode_telp' => $row['KODETELP']
	);
	
	$params_arr[$count][$index] = $param_temp;
	
	if($index == 2){
		$index = 0;
		$count++;
	} else $index++;
}

include($_SERVER['DOCUMENT_ROOT'].'/incofarming/Views/koperasi/cari-koperasi/search-koperasi-result_view.php');

?>